//
// Created on 2025/2/13.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#include "napi/native_api.h"
#include <string>

static napi_value NAPI_Global_say(napi_env env, napi_callback_info info) {
    napi_status status;
    size_t argc = 2;

    napi_value argv[2];
    napi_value thisVar;
    void *data;

    napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);

    napi_valuetype valueType;
    napi_typeof(env, argv[0], &valueType);

    napi_valuetype valueType_len;
    napi_typeof(env, argv[1], &valueType_len);

    double len;
    status = napi_get_value_double(env, argv[1], &len);
    if (status) {
        return nullptr;
    }

    int str_len = len;
    char buffer[str_len];
    size_t buffer_length = str_len;

    status = napi_get_value_string_utf8(env, argv[0], buffer, str_len, &buffer_length);
    if (status) {
        return nullptr;
    }

    std::string res_str = "get->";
    res_str.append(buffer);

    napi_value result;
    status = napi_create_string_utf8(env, res_str.c_str(), strlen(res_str.c_str()), &result);

    if (status) {
        return nullptr;
    }

    return result;
}
